/**
 * 
 */
Ext.define("mtons.main.controller.MainController", {
	extend : "Ext.app.Controller",
	alias : "widget.mainController",
	views : [ "IndexView", "MainView" ],
	refs : [ {
		ref : "mainView",
		selector : "mainView"
	}, {
		ref : "indexView",
		selector : "indexView"
	} ],
	init : function() {
		this.control({
			"treeMenu" : {
				itemclick : this.treeMenuItem
			}
		});
	},
	treeMenuItem : function(node, record, item, index, e, opts) {
		var moduleSN = record.raw.moduleSN;
		var moduleName = record.raw.moduleName;
		var moduleParams = record.raw.moduleParams;
		if (moduleSN) {

			var key = "mtons." + moduleName.toLowerCase();
			var value = getCTX() + "/" + moduleSN + "/"
					+ moduleName.toLowerCase();

			var module = "mtons." + moduleName.toLowerCase() + "." + moduleName
					+ "Module";

			Ext.Loader.setConfig({
				enabled : true
			});
			Ext.Loader.setPath(key, value);
			
			Ext.require(module, function() {
				Ext.create(module, moduleParams);
			});
		}
	}
});